<?php
//including header.php 
include '../../include/header.php';
//including page.php (It is a class which contain functions)
include '../../libraries/page.php';
//created object for page.php
$page = new page();
session_start();
//$userid = $_SESSION['userid'];
// checking the session
if (!$_SESSION['username']) {
    header("location:../user/login.php");
}
if ($_GET['q'] == 'logout') {
    $page->user_logout();
    header("location:../user/login.php");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    if ($_POST['chkDel'] == "") {
        $msg = $message[8];
    } else {
        $result = $page->delete("supplierid", "suppliers", $_POST['chkDel']);
        if ($result) {
            $msg = $message[2];
        } else {
            $msg = $message[0];
        }
    }
}
if ($_GET['status']) {
    $msg = $message[3];
}
$suppliers = 'active';
include '../../include/navbar.php';
?>

<!------------------css style sheets for responsive tables------------------------------------>
<link rel="stylesheet" type="text/css" href="../../css/suppliers/style_table.css">
<link rel="stylesheet" type="text/css" href="../../css/suppliers/responsive_table.css">


<br>

<!----------------------------------Display the result message of deletion--------------------->
<div  align="center"><? echo $msg; ?></div>

<!-------------------------------------------Group selection options----------------->
<div class="group_select_desk">
    <span><strong style="font-size:22px;">Suppliers</strong>
        <!---  <a onclick="javascript:checkAll('frmMain', false);" href="javascript:void();" style="float:right">uncheck all</a>
          <a onclick="javascript:checkAll('frmMain', true);" href="javascript:void();" style="float:right; margin-right: 20px;">check all</a></span>-->
        <a href="javascript:reserveCheck('chkDel[]')" style="float:right">Invert Select</a>
        <a href="javascript:allCheck('chkDel[]',false)" style="float:right; margin-right: 20px;">Select None</a> 
        <a href="javascript:allCheck('chkDel[]',true)" style="float:right; margin-right: 20px;">Select All</a></span>
</div>
<div class="group_select_mob">
    <span><strong style="font-size:22px;">Suppliers</strong>
        <div class="btn-group"  style="float: right">
            <a class="btn dropdown-toggle" data-toggle="dropdown" href="#" >
                Select&nbsp;
                <span class="caret"></span>
            </a>
            <ul class="dropdown-menu"  style="float:left;margin-left: -84px">
                <!-- dropdown menu links -->
                <li><a href="javascript:allCheck('chkDel[]',true)">Select All</a></li>
                <li><a href="javascript:allCheck('chkDel[]',false)">Select None</a></li> 
                <li><a href="javascript:reserveCheck('chkDel[]')" >Invert Select</a></li>
            </ul>
        </div>
    </span>
</div>
<br />

<!------------------------------Form------------------------------------->
<form name="frmMain" action="" method="post" OnSubmit="return onDelete();">

    <?
    //start the buffer
    ob_start();
    ?>

    <!------------------------------Details Table------------------------------------->
    <table  class="table1 table-striped" style="margin-left: auto;margin-right: auto; ">
        <thead  class="thead1">
            <tr>
                <th></th>
                <th>SL NO</th>
                <th>Name</th>
                <th>Address</th>
                <th>Street</th>
                <th>City</th>
                <th>State</th>
                <th>Mobile</th>
                <th>Phone</th>
                <th>TaxID Number</th>
                <th>Edit</th>
            </tr>
        </thead>
        <tbody>
            <?
            //php code to get the data from suppliers table 
            $suppliers = mysql_query("select * from suppliers");
            $id = 0;
            while ($suppliers_data = mysql_fetch_array($suppliers)) {

            $supplier_id = $suppliers_data['supplierid'];
            $name = ucwords(strtolower($suppliers_data['name']));
            $address = ucwords(strtolower($suppliers_data['address']));
            $street = ucwords(strtolower($suppliers_data['street']));
            $city = ucwords(strtolower($suppliers_data['city']));
            $state = ucwords(strtolower($suppliers_data['state']));
            $mobile = $suppliers_data['mobile'];
            $phone = $suppliers_data['phone'];
            $taxid = $suppliers_data['TaxIDNumber'];
            $id++;
            ?>

            <!-------------------------Dynamic row to display from database--------------------->
            <tr>
                <td><input type="checkbox" name="chkDel[]" id="chkDel<?= $i; ?>" value="<? echo $supplier_id; ?>"></td>
                <td><? echo $id; ?></td>
                <td><a href="supplier_update?id=<? echo $supplier_id; ?>"><? echo $name; ?></a></td>
                <td><? echo $address; ?></td>
                <td><? echo $street; ?></td>
                <td><? echo $city; ?></td>
                <td><? echo $state; ?></td>
                <td><? echo $mobile; ?></td>
                <td><? echo $phone; ?></td>
                <td><? echo $taxid; ?></td>
                <td><a href="supplier_update?id=<? echo $supplier_id; ?>">Edit</a></td>
            </tr>

            <?
            // Closing the loop
            }
            ?>
        </tbody>
    </table>

    <?
    //flush the buffer
    flush();
    ?>

    <!----------------------------CRUD Buttons-------------------------------------->
    <div align="center" style="margin-top: 10px">
        <a href="supplier_add"><button class="btn btn-primary" type="button">Add</button></a>
        <button class="btn btn-danger" type="submit">Delete</button>
    </div>
</form>
<?php
//including footer.php
include '../../include/footer.php';
?>

